package org.zsl.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zsl.dao.ProductMapper;
import org.zsl.model.Product;
import org.zsl.model.ResponseMessage;

import javax.sound.sampled.BooleanControl;
import java.util.List;

@Service
public class ProductService {

    @Autowired
    private ProductMapper productMapper;


    public List<Product> getList(){
        return  productMapper.selectAll();
    }

    public ResponseMessage remove(Integer productId){
        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = productMapper.delete(productId)>0;
        responseMessage.setSuccess(flag);

        return  responseMessage;
    }



    public  ResponseMessage edit(Product product){

        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = false;

        if(product.getProductId()==null||product.getProductId()==-1){
           flag=  productMapper.insert(product)>0;
        }else {
            flag = productMapper.update(product)>0;
        }

        responseMessage.setSuccess(flag);


        return  responseMessage;
    }


    public ResponseMessage onShelf(){
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setSuccess(false);

        return  responseMessage;
    }

}
